<?php
view_header('积分管理');
global $vue;
$url = '/point/admin/list';
// 初始化Vue数据
$vue->data("height", "");
$vue->created(["load()",]);
$vue->method("load()", "
this.height = 'calc(100vh - " . get_config('admin_table_height') . "px)';
");

$vue->method("view(row)", "
layer.open({
    type: 2,
    title: '积分详情',
    content: '/point/admin/his?user_id=' + row.user_id,
    area: ['80%', '80%'],
    maxHeight: '90%', 
    yes: function (index, layero) {
        layer.close(index);
    },
    end: function () {
        //app.load_list();
    }
});

");

$vue->method("submitForm()", "
    ajax('/point/admin/add',this.form,function(res){
    " . vue_message() . "
        if(res.code == 0){
            app.show_add = false;
            app.form = {};
            app.load_list();
        }
    })

");
$vue->data("show_add", false);

$vue->method("add()", "
    this.show_add = true;
");

// 权限控制
$vue->data("can_add", false);
$vue->data("can_edit", false);
$vue->data("can_del", false);

if (has_access('point/admin/add')) {
    $vue->data("can_add", true);
}
if (has_access('point/admin/edit')) {
    $vue->data("can_edit", true);
}
if (has_access('point/admin/delete')) {
    $vue->data("can_del", true);
} 

?>

<?php
$filter = [
    'data' => 'list',
    'url' => $url,
    'is_page' => true,
    'init' => true,
    [
        'type' => 'input',
        'name' => 'name',
        'attr_element' => [
            'placeholder' => lang('用户手机号'),
        ],
    ],
    [
        'type' => 'html',
        'html' => "
            <el-button type='primary' @click='add()'>发放积分</el-button> 
        "
    ]
];  
echo element("filter", $filter); 
?>
<div class="mt-0">
    <?php
    echo element('table', [
        ['name' => 'open', ':data' => 'list', ':height' => 'height'],
        [
            'name' => 'column',
            'prop' => 'name',
            'label' => lang('用户手机号'),
            'width' => '',
            'tpl' => [
                [
                    'type' => 'html',
                    "html" => "
                    <div>
                        <strong>{{scope.row.name}}</strong> 
                    </div>
                "
                ]
            ]
        ],
        [
            'name' => 'column',
            'prop' => 'point',
            'label' => lang('积分'),
            'width' => '300',
        ],

        [
            'name' => 'column',
            'prop' => 'id',
            'label' => lang('操作'),
            'width' => '160',
            'tpl' => [
                ['name' => 'button', 'label' => lang('查看'), '@click' => 'view(scope.row)', 'type' => 'info', 'size' => 'small', 'style' => 'margin-left: 5px;'],

            ]
        ],
        ['name' => 'close'],
    ]);
    ?>
</div>

<?php
echo element("pager", [
    'data' => 'list',
    'per_page' => get_config('per_page'),
    'per_page_name' => 'per_page',
    'url' => $url,
    'reload_data' => []
]);
?>

<el-dialog
    title="发放积分"
    :visible.sync="show_add"
    width="600px">

    <el-form :model="form" ref="form" label-width="120px" class="demo-ruleForm">
        <el-form-item label="用户手机号" prop="phone" required>
            <el-input v-model="form.phone" autocomplete="off" />
        </el-form-item>
        <el-form-item label="积分" prop="point" required>
            <el-input v-model="form.point" autocomplete="off" />
        </el-form-item>
        <el-form-item label="大标题" prop="title" required>
            <el-input v-model="form.title" autocomplete="off" />
        </el-form-item>
        <el-form-item label="描述" prop="desc">
            <el-input v-model="form.desc" autocomplete="off" />
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="submitForm()">确认</el-button>
        </el-form-item>
    </el-form>



</el-dialog>


<?php view_footer(); ?>